/**
 * 主循环程序
 */
const info = require("./information");
const prototype = require("./others/prototype");

const creepsrun = info.creepsrun;
const tower = info.tower;
const link = info.link;
const order = info.order;

// 修改原型
prototype();

module.exports.loop = function () {

    // 删除已死creep的memory记录
    for (let name in Memory.creeps) {
        if (!Game.creeps[name]) {
            delete Memory.creeps[name];
            console.log('Clearing non-existing creep memory:' + name);
        }
    }

    // creep运行
    creepsrun.forEach(run => run());

    // tower运行
    tower();

    // link运行
    link();

    // 订单运行
    order();

    // 转换bucket余量
    if (Game.cpu.bucket == 10000) {
        Game.cpu.generatePixel();
    }

    // 关闭打印
    Memory.log = false;
};